

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>docker-k8s-创建副本 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-21 14:00" pubdate>
        2020年12月21日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.5k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      22
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">docker-k8s-创建副本</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="通过命令创建（以后版本取消）"><a href="#通过命令创建（以后版本取消）" class="headerlink" title="通过命令创建（以后版本取消）"></a>通过命令创建（以后版本取消）</h2><pre><code class="hljs routeros">[root@node1 ~]# kubectl <span class="hljs-builtin-name">run</span> httpd-app <span class="hljs-attribute">--image</span>=httpd <span class="hljs-attribute">--replicas</span>=2
Flag --replicas has been deprecated, has <span class="hljs-literal">no</span> effect <span class="hljs-keyword">and</span> will be removed <span class="hljs-keyword">in</span> the future.
pod/httpd-app created
<span class="hljs-comment"># 提示以后的版本会删除此命令</span></code></pre>
<blockquote>
<p>查看副本运行情况</p>
</blockquote>
 <pre><code class="hljs routeros"> [root@node1 ~]# kubectl <span class="hljs-builtin-name">get</span> pod -o wide
NAME        READY   STATUS    RESTARTS   AGE   <span class="hljs-built_in"> IP </span>          NODE    NOMINATED NODE   READINESS GATES
httpd-app   1/1     Running   0          108s   10.244.2.2   node2   &lt;none&gt;           &lt;none&gt;
</code></pre>
<h2 id="通过-yml文件创建"><a href="#通过-yml文件创建" class="headerlink" title="通过 yml文件创建"></a>通过 yml文件创建</h2><blockquote>
<p>用deployment 创建一个简单的nginx</p>
</blockquote>
<pre><code class="hljs yaml">[<span class="hljs-string">root@node1</span> <span class="hljs-string">~</span>]<span class="hljs-comment"># vim nginx.yml</span>
<span class="hljs-attr">apiVersion:</span> <span class="hljs-string">apps/v1</span>  <span class="hljs-comment"># 这是api版本号 不同的apiVersion可以实现不同的功能</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Deployment</span> <span class="hljs-comment">#要创建的资源类型 如Deployment/Pod/ReplicaSet/StatefulSet/DaemonSet</span>
<span class="hljs-attr">metadata:</span> <span class="hljs-comment">#元数据对象 ，该资源的基本属性和信息</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">nginx-deployment</span> <span class="hljs-comment">#定义该资源的名称</span>
<span class="hljs-attr">spec:</span> <span class="hljs-comment">#定义期望状态</span>
  <span class="hljs-attr">selector:</span> <span class="hljs-comment"># </span>
    <span class="hljs-attr">matchLabels:</span> <span class="hljs-comment"># 标签选择器 和 selector共用</span>
     <span class="hljs-attr">app:</span> <span class="hljs-string">nginx</span> <span class="hljs-comment"># 标签名</span>
  <span class="hljs-attr">replicas:</span> <span class="hljs-number">5</span> <span class="hljs-comment">#创建的副本数量</span>
  <span class="hljs-attr">template:</span> <span class="hljs-comment"># 选择或创建的pod模板</span>
    <span class="hljs-attr">metadata:</span> <span class="hljs-comment"># Pod的元数据，Pod的信息</span>
      <span class="hljs-attr">labels:</span> <span class="hljs-comment"># pod的标签</span>
        <span class="hljs-attr">app:</span> <span class="hljs-string">nginx</span> <span class="hljs-comment">#标签名 这个app必须和上面指定的app的标签名一样，要不然不会在一个pod中 但是这个 app和nginx是可以随意写的只要和上面的相同即可</span>
    <span class="hljs-attr">spec:</span> <span class="hljs-comment"># 定义期望状态 ，详细的创建信息</span>
      <span class="hljs-attr">containers:</span> <span class="hljs-comment"># 定义容器的列表</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">nginx</span> <span class="hljs-comment">#容器名</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">nginx:1.8</span> <span class="hljs-comment"># 容器镜像</span>
        <span class="hljs-attr">ports:</span> <span class="hljs-comment">#端口</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">containerPort:</span> <span class="hljs-number">80</span> <span class="hljs-comment">#指定监控的端口</span></code></pre>
<blockquote>
<p>启动nginx副本</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@node1 ~]</span># kubectl apply -f nginx.yml 
deployment.apps/nginx-deployment created

# 查看
<span class="hljs-string">[root@node1 ~]</span># kubectl <span class="hljs-keyword">get</span> deployments.apps -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES      SELECTOR
nginx-deployment   <span class="hljs-number">5</span>/<span class="hljs-number">5</span>     <span class="hljs-number">5</span>            <span class="hljs-number">5</span>           <span class="hljs-number">97</span>s   nginx        nginx:<span class="hljs-number">1.8</span>   app=nginx
# 启动了<span class="hljs-number">5</span>个副本

<span class="hljs-string">[root@node1 ~]</span># kubectl <span class="hljs-keyword">get</span> pod -o wide
NAME                                READY   STATUS             RESTARTS   AGE     IP                NODE    NOMINATED NODE   READINESS GATES
nginx-deployment<span class="hljs-number">-5f</span>8c6846ff<span class="hljs-number">-4</span>x8nh   <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">23</span>m     <span class="hljs-number">10.244</span><span class="hljs-number">.2</span><span class="hljs-number">.3</span>        node2   &lt;none&gt;           &lt;none&gt;
nginx-deployment<span class="hljs-number">-5f</span>8c6846ff-fs82r   <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">23</span>m     <span class="hljs-number">10.244</span><span class="hljs-number">.1</span><span class="hljs-number">.3</span>        node3   &lt;none&gt;           &lt;none&gt;
nginx-deployment<span class="hljs-number">-5f</span>8c6846ff-mdrwq   <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">23</span>m     <span class="hljs-number">10.244</span><span class="hljs-number">.2</span><span class="hljs-number">.5</span>        node2   &lt;none&gt;           &lt;none&gt;
nginx-deployment<span class="hljs-number">-5f</span>8c6846ff-mrv2x   <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">23</span>m     <span class="hljs-number">10.244</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span>        node2   &lt;none&gt;           &lt;none&gt;
nginx-deployment<span class="hljs-number">-5f</span>8c6846ff-w5lbj   <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">23</span>m     <span class="hljs-number">10.244</span><span class="hljs-number">.1</span><span class="hljs-number">.2</span>        node3   &lt;none&gt;           &lt;none&gt;
</code></pre>

<h2 id="用daemonset创建一个-node-export"><a href="#用daemonset创建一个-node-export" class="headerlink" title="用daemonset创建一个 node-export"></a>用daemonset创建一个 node-export</h2><ul>
<li>其实和 docker run的命令差不多就是转换成 yml来写<pre><code class="hljs yaml">[<span class="hljs-string">root@node1</span> <span class="hljs-string">~</span>]<span class="hljs-comment"># vim node-export.yml</span>
<span class="hljs-attr">apiVersion:</span> <span class="hljs-string">apps/v1</span> <span class="hljs-comment"># 这是api版本号 不同的apiVersion可以实现不同的功能</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">DaemonSet</span>  <span class="hljs-comment">#要创建的资源类型 如Deployment/Pod/ReplicaSet/StatefulSet/DaemonSet</span>
<span class="hljs-attr">metadata:</span> <span class="hljs-comment">#元数据对象 ，该资源的基本属性和信息</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">node-exporter-daemonset</span> <span class="hljs-comment">#定义该资源的名称</span>
<span class="hljs-attr">spec:</span> <span class="hljs-comment">#定义期望状态</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">matchLabels:</span> <span class="hljs-comment"># 标签选择器 和 selector共用</span>
      <span class="hljs-attr">name:</span> <span class="hljs-string">promethues</span> <span class="hljs-comment"># 标签名</span>
  <span class="hljs-attr">template:</span> <span class="hljs-comment"># 选择或创建的pod模板</span>
    <span class="hljs-attr">metadata:</span>  <span class="hljs-comment"># Pod的元数据，Pod的信息</span>
      <span class="hljs-attr">labels:</span> <span class="hljs-comment"># pod的标签</span>
        <span class="hljs-attr">name:</span> <span class="hljs-string">promethues</span> <span class="hljs-comment">#标签名 这个name可以随便写 promethues也随便写</span>
    <span class="hljs-attr">spec:</span> <span class="hljs-comment"># 定义期望状态 ，详细的创建信息</span>
      <span class="hljs-attr">hostNetwork:</span> <span class="hljs-literal">true</span>  <span class="hljs-comment"># 表示直接使用节点中的主机网络，相当于docker的host网络</span>
      <span class="hljs-attr">containers:</span>   <span class="hljs-comment"># 定义容器的列表</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">node-exporter</span>  <span class="hljs-comment">#容器名</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">prom/node-exporter</span> <span class="hljs-comment"># 容器镜像</span>
        <span class="hljs-attr">imagePullPolicy:</span> <span class="hljs-string">IfNotPresent</span>  <span class="hljs-comment"># 容器的下载策略 （IfNotPresent(没有镜像时下&gt;载) | Never(从不下载) | Always(总是下载)）</span>
        <span class="hljs-attr">command:</span> <span class="hljs-comment"># 运行容器时执行的命令 运行程序==dockerfile中的ENTRYPOINT，或者docker run时最后跟的/bin/bash等命令，</span>
                 <span class="hljs-comment"># 会替代dockerfile中cmd和ENTRYPOINT执行的命令</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">/bin/node_exporter</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">--path.procfs</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">/host/proc</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">--path.sysfs</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">/host/sys</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">--collector.filesystem.ignored-mount-points</span>
        <span class="hljs-bullet">-</span> <span class="hljs-string">^/(sys|proc|dev|host|etc|)($|\)</span>
        <span class="hljs-attr">volumeMounts:</span>  <span class="hljs-comment"># 用来指定容器内的路径</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">proc</span> <span class="hljs-comment"># 定义路径名</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/host/proc</span> <span class="hljs-comment">#这里是容器真实的路径</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">sys</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/host/sys</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">root</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/rootfs</span>
</code></pre>
<blockquote>
<p>创建副本</p>
</blockquote>
<pre><code class="hljs crmsh">[root@node1 ~]<span class="hljs-comment"># kubectl apply -f node-export.yml </span>
daemonset.apps/<span class="hljs-keyword">node</span><span class="hljs-title">-exporter-daemonset</span> created

<span class="hljs-comment"># 查看</span>
[root@node1 ~]<span class="hljs-comment"># kubectl get daemonsets.apps -o wide</span>
NAME                      DESIRED   CURRENT   READY   UP-TO-<span class="hljs-keyword">DATE</span>   AVAILABLE   <span class="hljs-keyword">NODE</span> <span class="hljs-title">SELECTOR</span>   AGE   CONTAINERS      IMAGES               SELECTOR
<span class="hljs-keyword">node</span><span class="hljs-title">-exporter-daemonset</span>   <span class="hljs-number">2</span>         <span class="hljs-number">2</span>         <span class="hljs-number">0</span>       <span class="hljs-number">2</span>            <span class="hljs-number">0</span>           <span class="hljs-tag">&lt;none&gt;</span>          <span class="hljs-number">77s</span>   <span class="hljs-keyword">node</span><span class="hljs-title">-exporter</span>   prom/<span class="hljs-keyword">node</span><span class="hljs-title">-exporter</span>   <span class="hljs-attr">name=</span>promethues
<span class="hljs-comment"># 每个node主机各有一个pod</span>


[root@node1 ~]<span class="hljs-comment"># kubectl get pod -o wide</span>
NAME                                READY   STATUS             RESTARTS   AGE     IP                <span class="hljs-keyword">NODE</span>    <span class="hljs-title">NOMINATED</span> <span class="hljs-keyword">NODE</span>   <span class="hljs-title">READINESS</span> GATES
<span class="hljs-keyword">node</span><span class="hljs-title">-exporter-daemonset-59ncz</span>       <span class="hljs-number">0</span>/<span class="hljs-number">1</span>     CrashLoopBackOff   <span class="hljs-number">8</span>          <span class="hljs-number">20m</span>     <span class="hljs-number">192.168</span>.<span class="hljs-number">100.213</span>   node3   <span class="hljs-tag">&lt;none&gt;</span>           <span class="hljs-tag">&lt;none&gt;</span>
<span class="hljs-keyword">node</span><span class="hljs-title">-exporter-daemonset-84wpm</span>       <span class="hljs-number">0</span>/<span class="hljs-number">1</span>     CrashLoopBackOff   <span class="hljs-number">8</span>          <span class="hljs-number">20m</span>     <span class="hljs-number">192.168</span>.<span class="hljs-number">100.212</span>   node2   <span class="hljs-tag">&lt;none&gt;</span>           <span class="hljs-tag">&lt;none&gt;</span>
</code></pre>


</li>
</ul>
<h2 id="用Daemonset创建-CAdviser"><a href="#用Daemonset创建-CAdviser" class="headerlink" title="用Daemonset创建 CAdviser"></a>用Daemonset创建 CAdviser</h2><pre><code class="hljs yaml"><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">apps/v1</span> <span class="hljs-comment"># 这是api版本号 不同的apiVersion可以实现不同的功能</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">DaemonSet</span>  <span class="hljs-comment">#要创建的资源类型 如Deployment/Pod/ReplicaSet/StatefulSet/DaemonSet</span>
<span class="hljs-attr">metadata:</span> <span class="hljs-comment">#元数据对象 ，该资源的基本属性和信息</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">cadvisor</span> <span class="hljs-comment">#定义该资源的名称</span>
<span class="hljs-attr">spec:</span> <span class="hljs-comment">#定义期望状态</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">matchLabels:</span> <span class="hljs-comment"># 标签选择器 和 selector共用</span>
      <span class="hljs-attr">name:</span> <span class="hljs-string">cadvisor</span> <span class="hljs-comment"># 标签名</span>
  <span class="hljs-attr">template:</span> <span class="hljs-comment"># 选择或创建的pod模板</span>
    <span class="hljs-attr">metadata:</span>  <span class="hljs-comment"># Pod的元数据，Pod的信息</span>
      <span class="hljs-attr">labels:</span> <span class="hljs-comment"># pod的标签</span>
        <span class="hljs-attr">name:</span> <span class="hljs-string">cadvisor</span> <span class="hljs-comment">#标签名 这个name可以随便写 promethues也随便写</span>
    <span class="hljs-attr">spec:</span> <span class="hljs-comment"># 定义期望状态 ，详细的创建信息</span>
      <span class="hljs-attr">hostNetwork:</span> <span class="hljs-literal">true</span>  <span class="hljs-comment"># 表示直接使用节点中的主机网络，相当于docker的host网络</span>
      <span class="hljs-attr">containers:</span>   <span class="hljs-comment"># 定义容器的列表</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">cadvisor</span>  <span class="hljs-comment">#容器名 </span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">google/cadvisor</span> <span class="hljs-comment"># 容器镜像</span>
        <span class="hljs-attr">imagePullPolicy:</span> <span class="hljs-string">IfNotPresent</span>  <span class="hljs-comment"># 容器的下载策略 （IfNotPresent(没有镜像时下&gt;载) | Never(从不下载) | Always(总是下载)）</span>
        <span class="hljs-attr">volumeMounts:</span>  <span class="hljs-comment"># 用来指定容器内的路径</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">run</span> <span class="hljs-comment"># 定义路径名</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/var/run</span> <span class="hljs-comment">#这里是容器真实的路径</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">sys</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/sys</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">docker</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/var/lib/docker</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">root</span>
          <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/rootfs</span>
      <span class="hljs-attr">volumes:</span> <span class="hljs-comment"># 指定对应name的物理机路径,缩进与上方的containers对齐</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">run</span> <span class="hljs-comment">#对应 voluemMounts的name</span>
        <span class="hljs-attr">hostPath:</span> <span class="hljs-comment"># 主机的路径</span>
          <span class="hljs-attr">path:</span> <span class="hljs-string">/var/run</span> <span class="hljs-comment"># 制定主机内的路径 mount挂载到容器内</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">sys</span>
        <span class="hljs-attr">hostPath:</span>
          <span class="hljs-attr">path:</span> <span class="hljs-string">/sys</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">docker</span>
        <span class="hljs-attr">hostPath:</span>
          <span class="hljs-attr">path:</span> <span class="hljs-string">/var/lib/docker</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">root</span>
        <span class="hljs-attr">hostPath:</span>
          <span class="hljs-attr">path:</span> <span class="hljs-string">/</span>
</code></pre>
<blockquote>
<p>创建副本</p>
</blockquote>
 <pre><code class="hljs angelscript"><span class="hljs-string"> [root@node1 ~]</span># kubectl apply -f cadvistor.yml 
 daemonset.apps/cadvisor created

 ## 查看
<span class="hljs-string"> [root@node1 ~]</span># kubectl <span class="hljs-keyword">get</span> daemonsets.apps -o wide
NAME                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE     CONTAINERS      IMAGES               SELECTOR
cadvisor                  <span class="hljs-number">2</span>         <span class="hljs-number">2</span>         <span class="hljs-number">2</span>       <span class="hljs-number">2</span>            <span class="hljs-number">2</span>           &lt;none&gt;          <span class="hljs-number">4</span>m10s   cadvisor        google/cadvisor      name=cadvisor


<span class="hljs-string">[root@node1 ~]</span># kubectl <span class="hljs-keyword">get</span> pod -o wide
NAME                                READY   STATUS             RESTARTS   AGE     IP                NODE    NOMINATED NODE   READINESS GATES
cadvisor-mm4wn                      <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">4</span>m37s   <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.213</span>   node3   &lt;none&gt;           &lt;none&gt;
cadvisor-pfzms                      <span class="hljs-number">1</span>/<span class="hljs-number">1</span>     Running            <span class="hljs-number">0</span>          <span class="hljs-number">4</span>m37s   <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.212</span>   node2   &lt;none&gt;           &lt;none&gt;
</code></pre>






<h2 id="查看pod方法"><a href="#查看pod方法" class="headerlink" title="查看pod方法"></a>查看pod方法</h2><pre><code class="hljs vala">kubectl <span class="hljs-keyword">get</span> deployments.apps -o wide 
<span class="hljs-meta"># 可以查看到 以deployment运行的副本</span>

Kubectl <span class="hljs-keyword">get</span> rs 
<span class="hljs-meta"># 可以查看到deployment创建的副本数量（Replicaset）	</span>

Kubect <span class="hljs-keyword">get</span> pod –o wide
<span class="hljs-meta"># 查看已运行的pod</span>

Kubectl <span class="hljs-keyword">get</span> pod --show-labels
<span class="hljs-meta"># 查看pod的labels标签</span>

Kubect delete –f nginx.yml
<span class="hljs-meta"># 删除使用文件创建的deployment的方法</span>

kubectl describe pod nginx-deployment
<span class="hljs-meta"># 查看pod创建的过程</span>
</code></pre>

















            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/docker/">docker</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/k8s/">k8s</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/12/21/docker-k8s/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">docker-k8s理论</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/17/docker-swarm/">
                        <span class="hidden-mobile">docker-swarm集群</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "docker-k8s-创建副本&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
